﻿Imports System.ComponentModel
Imports System.Text


Imports DevExpress.Skins
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraBars.Ribbon.Gallery
Imports BUS
Imports DTO
Imports DevExpress.XtraSplashScreen
Imports System.IO

Partial Public Class frmMain
    Inherits DevExpress.XtraBars.Ribbon.RibbonForm

    Private frmName As String = "Phần Mền Quản Lý Bán Hàng"

    Shared Sub New()

    End Sub

    Public Sub New()
        DevExpress.UserSkins.BonusSkins.Register()
        DevExpress.Skins.SkinManager.EnableFormSkins()
        InitializeComponent()
    End Sub


    'Hàm thêm 1 tab mới. truyền vào 1 user control tương ứng vs chức năng đó
    Public Sub AddTab(TagName As String, TabText As String, UserControl As System.Windows.Forms.UserControl)
        For Each tab As DevExpress.XtraTab.XtraTabPage In tabMain.TabPages
            If tab.Name = TagName And tab.Text = TabText Then
                tabMain.SelectedTabPage = tab
                Return
            End If
        Next
        Dim TAbAdd As New DevExpress.XtraTab.XtraTabPage()
        TAbAdd.Text = TabText
        TAbAdd.Name = TagName
        TAbAdd.Controls.Add(UserControl)
        UserControl.Dock = DockStyle.Fill
        tabMain.TabPages.Add(TAbAdd)
    End Sub



    Private Sub tabMain_CloseButtonClick(sender As Object, e As EventArgs) Handles tabMain.CloseButtonClick
        Dim tabControl As DevExpress.XtraTab.XtraTabControl = TryCast(sender, DevExpress.XtraTab.XtraTabControl)
        Dim arg As DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs = TryCast(e, DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)
        TryCast(arg.Page, DevExpress.XtraTab.XtraTabPage).Dispose()
    End Sub
    Public Shared maND As String
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SplashScreenManager.ShowForm(GetType(SplashScreen1), True, True)
        'WebBrowser1.Navigate(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) & "help_qlbh.htm")
        Dim appPath As String
        appPath = Application.StartupPath
        WebBrowser1.Navigate(appPath & "/help_qlbh.htm")
        DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = "Blue"
        Me.Text = frmName
        tmrDayNow.Start()
        lbQuyen.Caption = NguoiDungBUS.layQuyenCuaND(maND)
        lbSeverName.Caption = HeThongBUS.layTenSever()
        lbDatabaseName.Caption = HeThongBUS.layDataBase()

        SplashScreenManager.CloseForm()

        

    End Sub

    Private Sub tmrDayNow_Tick(sender As Object, e As EventArgs) Handles tmrDayNow.Tick
        lbDate.Caption = DateTime.Now.ToShortDateString
        lbTime.Caption = DateTime.Now.ToLongTimeString
    End Sub

    Private Sub btnThongTin_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnThongTin.ItemClick
        Dim frm As New frmThongTin()
        frm.ShowDialog()
    End Sub

    Private Sub btnPhanQuyen_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnPhanQuyen.ItemClick
        Dim pq As New PhanQuyenNhonNDDTO
        pq = ChucNangBUS.layQuyenCuaND(maND, 5)
        If pq.TruyCap = True Then
            Dim uc As New ucPhanQuyen
            AddTab("tabPhanQuyen", barbtnPhanQuyen.Caption, uc)
            Me.Text = barbtnPhanQuyen.Caption + " - " + frmName
            HeThongBUS.themNhatKy(maND, "Phân Quyền", "Xem", "")
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Bạn không có quyền vào mục này", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If

    End Sub

    Private Sub tabMain_ControlAdded(sender As Object, e As ControlEventArgs) Handles tabMain.ControlAdded
        tabMain.SelectedTabPageIndex = tabMain.TabPages.Count - 1
    End Sub

    Private Sub barbtnNhatKy_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNhatKy.ItemClick
        Dim pq As PhanQuyenNhonNDDTO = ChucNangBUS.layQuyenCuaND(maND, 9)
        If pq.TruyCap = True Then
            Dim uc As New ucNhatKyHeThong
            AddTab("tabNhatKy", barbtnNhatKy.Caption, uc)
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Bạn không có quyền vào mục này", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If
    End Sub


    Private Sub barbtnSaoLuu_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnSaoLuu.ItemClick
        Dim pq As PhanQuyenNhonNDDTO = ChucNangBUS.layQuyenCuaND(maND, 11)
        If pq.TruyCap = True Then
            Dim frm As New frmSaoLuuDuLieu
            frm.ShowDialog()
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Bạn không có quyền vào mục này", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If
    End Sub

    Private Sub barbtnSuaChua_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnSuaChua.ItemClick
        DevExpress.XtraEditors.XtraMessageBox.Show("Chức năng đang xây đựng")
    End Sub

    Private Sub barbtnDoiMatKhau_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnDoiMatKhau.ItemClick
        Dim pq As PhanQuyenNhonNDDTO = ChucNangBUS.layQuyenCuaND(maND, 8)
        If pq.TruyCap = True Then
            Dim frm As New frmDoiMatKhau
            frm.ShowDialog()
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Bạn không có quyền vào mục này", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If

    End Sub

    Private Sub barbtnKhuVuc_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnKhuVuc.ItemClick
        Dim uc As New ucKhuVuc
        AddTab("tabKhuVuc", barbtnKhuVuc.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnKhuVuc.Caption)
    End Sub


    Private Sub barfrmKhoiPhuc_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barfrmKhoiPhuc.ItemClick
        Dim pq As PhanQuyenNhonNDDTO = ChucNangBUS.layQuyenCuaND(maND, 12)
        If pq.TruyCap = True Then
            Dim frm As New frmPhucHoi
            frm.ShowDialog()
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Bạn không có quyền vào mục này", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If
    End Sub

    Private Sub barbtnKhachHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnKhachHang.ItemClick
        Dim uc As New ucKhachHang
        AddTab("tabKhachHang", barbtnKhachHang.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnKhachHang.Caption)
    End Sub

    Private Sub barbtnNhaCungCap_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNhaCungCap.ItemClick
        Dim uc As New ucNhaCungCap
        AddTab("tabNhaCungCap", barbtnNhaCungCap.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnNhaCungCap.Caption)
    End Sub

    Private Sub barbtnKhoHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnKhoHang.ItemClick
        Dim uc As New ucKhoHang
        AddTab("tabKhoHang", barbtnKhoHang.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnKhoHang.Caption)
    End Sub

    Private Sub barbtnDonViTinh_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnDonViTinh.ItemClick
        Dim uc As New ucDonViTinh
        AddTab("tabDonViTinh", barbtnDonViTinh.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnDonViTinh.Caption)
    End Sub

    Private Sub barbtnNhomHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNhomHang.ItemClick
        Dim uc As New ucNhomHang
        AddTab("tabNhomHang", barbtnNhomHang.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnNhomHang.Caption)
    End Sub

    Private Sub barbtnHangHoa_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnHangHoa.ItemClick
        Dim uc As New ucHangHoa
        AddTab("tabHangHoa", barbtnHangHoa.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnHangHoa.Caption)
    End Sub

    Private Sub barbtnTyGia_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnTyGia.ItemClick
        Dim uc As New ucTyGia
        AddTab("tabTyGia", "Tiền tệ", uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnTyGia.Caption)
    End Sub

    Private Sub barbtnBoPhan_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnBoPhan.ItemClick
        Dim uc As New ucBoPhan
        AddTab("tabBoPhan", barbtnBoPhan.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnBoPhan.Caption)
    End Sub

    Private Sub barbtnNhanVien_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNhanVien.ItemClick
        Dim uc As New ucNhanVien
        AddTab("tabNhanVien", barbtnNhanVien.Caption, uc)
        HeThongBUS.themNhatKy(maND, "Danh Mục", "Xem", barbtnNhanVien.Caption)
    End Sub

    Private Sub barbtnMuaHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnMuaHang.ItemClick
        Dim uc As New ucMuaHang
        AddTab("tabMuaHang", barbtnMuaHang.Caption, uc)
        Me.Text = barbtnMuaHang.Caption + " - " + frmName
    End Sub

    Private Sub barbtnChuyenKho_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnChuyenKho.ItemClick
        Dim uc As New ucChuyenKho
        AddTab("tabChuyenKho", barbtnChuyenKho.Caption, uc)
        Me.Text = barbtnChuyenKho.Caption + " - " + frmName
    End Sub

    Private Sub barbtnBanHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnBanHang.ItemClick
        Dim uc As New ucBanHang
        AddTab("tabBanHang", barbtnBanHang.Caption, uc)
        Me.Text = barbtnBanHang.Caption + " - " + frmName
    End Sub

    Private Sub barbtnTonKho_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnTonKho.ItemClick
        Dim uc As New ucTonKho
        AddTab("tabTonKho", barbtnTonKho.Caption, uc)
        Me.Text = barbtnTonKho.Caption + " - " + frmName
    End Sub

    Private Sub barbtnThuTien_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnThuTien.ItemClick
        Dim uc As New ucThuTien
        AddTab("tabThuTien", barbtnThuTien.Caption, uc)
        Me.Text = barbtnThuTien.Caption + " - " + frmName
    End Sub

    Private Sub barbtnTraTien_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnTraTien.ItemClick
        Dim uc As New ucTraTien
        AddTab("tabTraTien", barbtnTraTien.Caption, uc)
        Me.Text = barbtnTraTien.Caption + " - " + frmName
    End Sub

    Private Sub barbtnTongHop_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnTongHop.ItemClick
        Dim uc As New ucBaoCaoTongHop
        AddTab("tabTongHop", barbtnTongHop.Caption, uc)
        Me.Text = barbtnTongHop.Caption + " - " + frmName
    End Sub

    Private Sub barbtnDoanhThu_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnDoanhThu.ItemClick
        Dim uc As New ucDoanhThu
        AddTab("tabDoanhThu", barbtnDoanhThu.Caption, uc)
        Me.Text = barbtnDoanhThu.Caption + " - " + frmName
    End Sub


    Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick
        Dim frm As New frmThongTinDoAn
        frm.ShowDialog()
    End Sub


    Private Sub barbtnExit_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnExit.ItemClick
        Me.Close()
        Dim t As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf Thear))
        t.SetApartmentState(System.Threading.ApartmentState.STA)
        t.Start()
    End Sub

    Private Sub Thear()
        Dim frm As New frmDangNhap()
        Application.Run(frm)
    End Sub

    Private Sub RibbonControl_Click(sender As Object, e As EventArgs) Handles RibbonControl.Click

    End Sub

    Private Sub BarButtonItem5_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem5.ItemClick
        Dim uc As New ucTroGiup
        AddTab("tabTroGiup", BarButtonItem5.Caption, uc)
        Me.Text = BarButtonItem5.Caption + " - " + frmName
    End Sub
End Class
